﻿using System.Collections.Generic;
using System.Linq;
using Missbot.Common;
using Missbot.Service;
using Dolany.UtilityTool;
using Missbot.AIModule.OnlineStore;

namespace Missbot.AIModule.Pet.Cooking
{
    public class CookingDiet : DbBaseEntity
    {
        public string Name { get; set; }

        public int Level { get; set; }

        public string Description { get; set; }

        public Dictionary<string, int> Materials { get; set; }

        public Dictionary<string, int> Flavorings { get; set; }

        public int Exp { get; set; }

        public string[] Attributes { get; set; }

        public string ExchangeHonor { get; set; }
    }

    public static class CookingDietDA
    {
        public static int EstimatedPrice(this CookingDiet entity)
        {
            return entity.Materials.Sum(p => AutofacSvc.Resolve<HonorSvc>().FindItem(p.Key).Price * p.Value) + entity.Flavorings.Sum(p => p.Value) * 20;
        }

        public static string Format(this CookingDiet entity)
        {
            var strList = new List<string> {entity.Name, $"    {entity.Description}", $"需要等级：{entity.Level}"};
            if (!entity.Materials.IsNullOrEmpty())
            {
                strList.Add($"需要材料：{string.Join(",", entity.Materials.Select(m => $"{m.Key}×{m.Value}"))}");
            }

            if (!entity.Flavorings.IsNullOrEmpty())
            {
                strList.Add($"需要调味料：{string.Join(",", entity.Flavorings.Select(m => $"{m.Key}×{m.Value}"))}");
            }
            
            strList.Add($"可提供经验值：{entity.Exp}");
            strList.Add($"特性：{string.Join(",", entity.Attributes)}");
            strList.Add($"可使用【{entity.ExchangeHonor}】兑换");
            return string.Join("\n", strList);
        }

        public static List<CookingDiet> GetAll()
        {
            return MongoService<CookingDiet>.Get();
        }
    }
}